package ranveterinaria.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ranveterinaria.modelo.PromocionModelo;
import ranveterinaria.negocio.GestionProducto;
import ranveterinaria.negocio.GestionPromocion;

@WebServlet("/PromocionListar")
public class PromocionListar extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public PromocionListar() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GestionPromocion negocio = new GestionPromocion();
		try {

			Collection<PromocionModelo> lista = negocio.listar();

			request.setAttribute("arregloProductos", new GestionProducto().listar());
			request.setAttribute("arreglo", lista);
			RequestDispatcher rd = request.getRequestDispatcher("Formularios/Promocion.jsp");
			rd.forward(request, response);

		} catch (ranveterinaria.excepcion.DAOExcepcion e) {
			request.setAttribute("MENSAJEERROR", e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("Formularios/Promocion.jsp");
			rd.forward(request, response);	
		} catch (Exception e) {
			request.setAttribute("MENSAJEERROR", e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("Formularios/Promocion.jsp");
			rd.forward(request, response);	
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GestionPromocion negocio = new GestionPromocion();
		try {

			Collection<PromocionModelo> lista = negocio.listar();

			request.setAttribute("arregloProductos", new GestionProducto().listar());
			request.setAttribute("arreglo", lista);
			RequestDispatcher rd = request.getRequestDispatcher("Formularios/Promocion.jsp");
			rd.forward(request, response);

		} catch (Exception e) {
			request.setAttribute("MENSAJEERROR", e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("Formularios/Promocion.jsp");
			rd.forward(request, response);	
		}
	}

}
